package com.github.shiqiyue.eatest.util;

import java.util.Random;

/***
 * 字符串随机生成
 * @author wenyao.wu
 * @date 2018/7/12
 */
public class StringRandom {

    public static final char[] LETTERS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    public static final char[] NUMBERS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    public static final char[] LETTERS_AND_NUMBERS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    private static final Random random = new Random();


    public static String random(char[] seed, int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("length must larger than 0");
        }
        char[] result = new char[length];
        for (int i = 0; i < length; i++) {
            result[i] = seed[Math.max(random.nextInt(length) - 1, 0)];
        }
        return new String(result);
    }


}
